<?php
/**
 * Geneone: Content Management Framework
 * User Namespace Search Result Object
 *
 * http://geneone.neondragon.net/
 *
 * @package Geneone
 * @author Khlo
 * @version 1.0
 * @copyright 2004-2006 Geneone Development Team
 */
 
class Gene_Search_Result_User {
	var $q;
	var $perPage = 10;
	var $numResults;
	
	/**
	 * Initializes the class.
	 *
	 * @var object $q Database Query
	 * @var string $phrase Search Phrase
	 */
	function Gene_Search_Result_User($q, $phrase) {
		$this->q =& $q;
		$this->phrase = $phrase;
	}
	
	/**
	 * Sets the number of results to display on a page.
	 *
	 * @var integer $perPage Results per page
	 */
	function setPerPage($perPage) {
		$this->perPage = $perPage;
	}
	
	/**
	 * @return integer total number of results
	 */
	function getNumResults() {
		if ($this->numResults === null) {
			$this->numResults = $this->q->numRows();
		}
		
		return $this->numResults;
	}
	
	/**
	 * @return integer number of pages required to display all results
	 */
	function getNumPages() {
		return ceil($this->getNumResults()/$this->perPage);
	}
	
	/**
	 * Returns results for a specific page.
	 *
	 * @var integer $page Page number
	 *
	 * @return array Search results for page
	 */
	function getPagedResults($page=1) {
		$start = ($page-1)*$this->perPage;
		$this->q->seek($start);
		$results = array();
		
		$i = 0;
		$c = true;
		while ($i < $this->perPage && $c) {
			$row = $this->q->fetchRow();
			
			if ($row) {
				$results[] = array(
					"title" => $row['name'],
					"snippet" => $row['bio'],
					"url" => Gene::makeLink(Gene::userID($row['name'])),
				);
			} else {
				$c = false;
			}
			
			++$i;
		}
		
		return $results;
	}
}
 
?>